<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const curry = (fn, ...args) =>
            args.length >= fn.length
                // 传入的参数大于等于原始函数fn的参数个数，则直接执行该函数
                ? fn(...args)
                //传入的参数小于原始函数fn的参数个数时
                //则继续对当前函数进行柯里化，返回一个接受所有参数的函数
                : (..._args) => curry(fn, ...args, ..._args);
        function getSum(x, y, z) {
            return x + y + z
        }
        const add = curry(getSum)
        console.log(add(1, 2, 3))
        console.log(add(1)(2)(3))
        console.log(add(1, 2)(3))
        console.log(add(1)(2, 3))
    </script>
</body>

</html>